<script>
    common.setMainTitle('Danh sách người dùng');
</script>
<?php 
$trangthai = array(
'2' => "",
'0' => "",
'approved' => ""
);
$trangthai[$this->phamvi] = "checked='true'"; 
 ?>
<form id="mainform" name='frm' method=post action="">
    <table width = 100% id="id-form">
        <tr>
            <td width="10%" nowrap="nowrap">Tên đăng nhập
            </td>
            <td >
                <input type=text class="inp-form" name=USERNAME value="<?=$this->USERNAME?>" size=25>
            </td>
        </tr>
        <tr>
            <td nowrap="nowrap">Trạng thái</td>
            <td>
                Tất cả&nbsp;&nbsp; <input type="radio" <?php echo $trangthai['2']; ?> onclick="timkiemAction()" name="phamvi" value="2" />&nbsp;&nbsp;
                Chưa kích hoạt&nbsp;&nbsp;<input type="radio" <?php echo $trangthai['0']; ?> name="phamvi" onclick="timkiemAction()" value="0" />&nbsp;&nbsp;
                Đã kích hoạt&nbsp;&nbsp;<input type="radio" name="phamvi" value="approved" <?php echo $trangthai['approved']; ?> onclick="timkiemAction()" />
            </td>
        </tr>
        <tr>
            <td nowrap="nowrap"></td>
            <td nowrap="nowrap" colspan="3"><input type='button' onclick="timkiemAction()" value="Tìm kiếm">
        <!-- <input type=submit value="Tìm lại">-->
            </td>
        </tr>
    </table >
    <table style="margin-top: 10px" border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <thead>
            <tr class="alternate-row">
                <th width="5%" style="text-align: center" nowrap="nowrap">STT</th>
                <th width="5%" style="text-align: center" nowrap valign="left">
                    <input type=checkbox name=DELALL onclick="SelectAllU(this,'DEL')">
                </th>
                <th width="25%" style="text-align: left">TÊN ĐĂNG NHẬP</th>
                <th width="25%" style="text-align: left">HỌ TÊN</th>
                <th width="" style="text-align: left">EMAIL</th>
                <th style="text-align: center" width="10%" style="text-align: left">KÍCH HOẠT</th>
            </tr>
        </thead>
        <tfoot>
        </tfoot>
        <tbody>
            <?php
            if(count($this->data)==0){
				echo "<tr><td colspan=6>Không có dữ liệu nào được tìm thấy</td></tr>";
            } else {
                $stt = 1;
            }
            //var_dump($this->data);exit;
            foreach($this->data as $item){?>
            <tr>
                <td style="text-align: center" ><?=$stt?></td>
                <td style="text-align: center">
                    <input id="<?=$item['ID_U']?>" type="checkbox" name="DEL[]" value="<?=$item['ID_U']?>" />
                </td>
                <td> <a href="#" onClick="ItemClickU(<?php echo $item['ID_U'] ?>)">
                        <?=$item['USERNAME'];?></a>
                </td>
                <td> <a href="#" onClick="ItemClickU(<?php echo $item['ID_U'] ?>)">
                        <?=$item['FULLNAME'];?></a>
                </td>
                <td> <a href="#" onClick="ItemClickU(<?php echo $item['ID_U'] ?>)">
                        <?=$item['EMAIL'];?></a>
                </td>
                <td style="text-align: center"><span id="status<?=$item['ID_U']?>"> <a href="#" onClick="capnhatactive(<?php echo $item['ID_U'] ?>)">
                        
                        <?php if($item['STATUS']!='approved') {
                            echo '<font color="#004FA0"> Active </font>';
                        } else {
                            echo 'OK';
                        }?></a>
                    </span>
                </td>
            </tr>
            <?php $stt++;}?>
        </tbody>
    </table>
</form>
<script>
    function ItemClickU(id)
    {
         document.frm.action = "/admin/users/input/id/"+id;
         document.frm.submit();
    }
    function SelectAllU(selobj,childobj){
         var arr = document.getElementsByName(childobj+"[]");
         for(var i=0;i<arr.length;i++){
            arr[i].checked = selobj.checked;
         }
    }
    function del()
     {
            var ln = 0;
            var arr = document.getElementsByName('DEL[]');
            for(var i = 0 ; i < arr.length ;i++ )
            {

                    if(arr[i].checked == true)
                    {
                            ln = 1;
                            break;
                    }
            }
            if(ln == 1)
            {
                    if(confirm("<?php echo "Bạn có muốn xóa không"; ?>")){
                            document.frm.action="/admin/users/delete";
                            document.frm.method="post";
                            document.frm.submit();
                    }
            }
            else
            {
                    alert("Bạn phải một dòng chọn để xóa");
            }
     }
    function timkiemAction(){
        common.submitForm(document.frm,'');
    }
    function add(){
        document.location.href='/admin/users/input';
    }
     /* update active (ajax) */
    //Gui thong tin status len server
    function capnhatactive(varid){
        var id = document.getElementById(varid).value;
        var valueActive = 1;
        jx.setParameter('active',valueActive);
        jx.setParameter('id_u',id);
        jx.success('capnhatsuccess');
        jx.request('/admin/users/active','POST');
    }
    function capnhatsuccess(){
        if(res == 1)
        {
            var status = document.getElementById("status"+id_u);
            status.innerHTML = "OK";
        }
    }
</script>
